﻿@model Wicresoft.UnifyShow.Business.SFUser_XModel
@{
    ViewBag.Title = "创建用户";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
    List<string> sites = (List<string>)ViewData["Sites"];
}
<div class="right_title2">
    <a href="/Navigate/Index">首页</a> ><span>创建用户</span></div>
<div class="index_lr">
    @if (ViewBag.Post)
    {
        <input type="hidden" value="@ViewBag.Status" id="CreateStatus" />
        <input type="hidden" value="@ViewBag.ResultStr" id="ResultStr" />
        <script type="text/javascript">

            $(document).ready(function () {
                var status = parseInt($("#CreateStatus").val());
                var resultStr = $("#ResultStr").val();
                var error = "连接错误，无法成功添加此用户，请重新点击添加，或联系管理员。"
                if (resultStr != "") error += ("(" + resultStr + ")");
                switch (status) {
                    case 0:
                        $("#resetForm").click();
                        alert("添加成功。");
                        break;
                    case 1:
                        alert("集中展现" + error);
                        break;
                    case 2:
                        alert("自服务" + error);
                        break;
                    case 3:
                        alert("ITSM" + error);
                        break;
                    case 4:
                        alert("认证服务" + error);
                        break;
                    default:
                        alert("服务器" + error);
                }

            });
        </script> 
    }
    <ul>
        <li class="index_lr2_M">
            <div class="index_lrA_title ui-icons">
                <h3>
                    创建用户</h3>
            </div>
            @using (Html.BeginForm())
            {
                <div class="index_pt_bg">
                    <table id="inputs">
                        <tbody>
                            <tr>
                                <td width="350">
                                    <label>
                                        <b>姓名<font class="err">*</font>：</b></label>@Html.EditorFor(o => o.DisplayName)
                                </td>
                                <td width="380">
                                    <label>
                                        <b>公司<font class="err">*</font>：</b></label><select name="company" id="company">
                                            @if (string.IsNullOrWhiteSpace(Model.Company))
                                            {
                                                foreach (var item in sites)
                                                {
                                                <option value="@item">@item</option>
                                                }
                                            }
                                            else
                                            {
                                                foreach (var item in sites)
                                                {
                                                    if (string.Equals(item, Model.Company))
                                                    {
                                                <option value="@item" selected="selected">@item</option>
                                                    }
                                                    else
                                                    {
                                                <option value="@item">@item</option>
                                                    }
                                                }
                                            }
                                        </select>
                                </td>
                            </tr>
                            <tr>
                                <td width="350">
                                    <label>
                                        <b>登录名<font class="err">*</font>：</b></label>@Html.EditorFor(o => o.Name)
                                </td>
                                <td width="380">
                                    <label>
                                        <b>手机<font class="err">*</font>：</b></label>@Html.EditorFor(model => model.Mobile)
                                </td>
                            </tr>
                            <tr>
                                <td width="350">
                                    <label>
                                        <b>密码<font class="err">*</font>：</b></label><input type="password" id="Password" name="Password" value="@Model.Password" />
                                </td>
                                <td width="380">
                                    <label>
                                        <b>确认<font class="err">*</font>：</b></label><input type="password" id="ConfirmPassword" name="ConfirmPassword" value="@Model.ConfirmPassword" />
                                </td>
                            </tr>
                            <tr>
                                <td width="350">
                                    <label>
                                        <b>邮箱<font class="err">*</font>：</b></label>@Html.EditorFor(model => model.Email)
                                </td>
                                <td width="410">
                                    <label>
                                        <b>部门<font class="err">*</font>：</b></label>@Html.EditorFor(model => model.Department)（部门应为ITSM存在部门） 
                                </td>
                            </tr>
                            <tr>
                                <td width="350">
                                    <label>
                                        <b>职务<font class="err">*</font>：</b></label>@Html.EditorFor(model => model.Position)
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <p>
                        <input type="submit" value="添加" id="addSubmit" />
                        <input type="button" value="重置" id="resetForm" />
                    </p>
                </div>
            }
        </li>
    </ul>
</div>
@section LeftMenu{
    <li class="VNavLeaf ui-icons">创建用户</li>
    <li><a href="@Url.Action("Index", "AdminPermission")">配置用户</a></li>
    <li><a href="@Url.Action("Add", "AdminBS")">添加业务系统</a></li>
    <li><a href="@Url.Action("Index", "AdminBSMaintain")">维护业务系统</a></li>
    <li><a href="@Url.Action("Admin", "AdminDocument")">常用资源管理</a></li>
    <li><a href="@Url.Action("Index", "AdminOther")">其他管理</a></li>
    @*Javascript向导 参考  当UserSites.count>3时，一次取出，否则分别取出。可以仿造权限 来选择 业务系统范围    
    device 增删改查  列表  通过dialog 进行增加和 编辑*@
}
@section ScriptAndCss{
    <style>
        label
        {
            float: left;
            width: 80px;
            text-align: right;
        }
        .fieldset1 input
        {
            float: left;
        }
        input[type="password"]
        {
            width: 142px;
        }
    </style>
    <script type="text/javascript">
        function clearForm() {
            $("#company", "#inputs")[0].selectedIndex = 0;
            $("input", "#inputs").each(function () {
                $(this).val("");
            });
        }
        var error11 = false;
        $(document).ready(function () {
            $("form").submit(function () {

                if (error11) {
                    alert("登录名已经存在，请重新输入。");
                    return false;
                }

                var error = ""
                if ($("#DisplayName").val() == "") error += "用户名不能为空。";
                if ($("#Name").val() == "") error += "登录名不能为空。";
                if ($("#Mobile").val() == "") error += "手机不能为空。";
                if ($("#Password").val() == "") error += "密码不能为空。";
                if ($("#Email").val() == "") error += "邮箱不能为空。";
                if ($("#Department").val() == "") error += "部门不能为空。";
                if ($("#Position").val() == "") error += "职务不能为空。";
                if ($("#ConfirmPassword").val() != $("#Password").val()) error += "两次密码输入不一致。";

                if (error != "") {
                    alert(error);
                    return false;
                }
                return true;
            });
            $("#Name").focusout(function () {
                if ($(this).val() != "") {
                    $.post('@Url.Action("Exist", "AdminPermission")', "name=" + $(this).val(), function (data) {
                        if (data == true) {
                            error11 = true;
                            alert("登录名已经存在，请重新输入。");
                            $(this).focus();
                        }
                        else {
                            error11 = false;
                        }
                    });
                }
            });

            $("#resetForm").click(function () {
                clearForm();
            });
        });    
    
    </script>
}
